import numpy as np
import pandas as pd
#input data
train = pd.read_csv("pima-indians-diabetes.csv")
print(train.head())

#查看缺失值较多的数据统计
NaN_col_names = ['Plasma_glucose_concentration','blood_pressure','Triceps_skin_fold_thickness','serum_insulin','BMI']
train[NaN_col_names] = train[NaN_col_names].replace(0, np.NaN)
print(train.isnull().sum())


#中值补充确实值
medians = train.median() 
train = train.fillna(medians)

print(train.isnull().sum())


#  get labels
y_train = train['Target']   
X_train = train.drop(["Target"], axis=1)

#用于保存特征工程之后的结果
feat_names = X_train.columns

# 数据标准化
from sklearn.preprocessing import StandardScaler

# 初始化特征的标准化器
ss_X = StandardScaler()

# 分别对训练和测试数据的特征进行标准化处理
X_train = ss_X.fit_transform(X_train)

#存为csv格式
X_train = pd.DataFrame(columns = feat_names, data = X_train)

train = pd.concat([X_train, y_train], axis = 1)

train.to_csv('FE_pima-indians-diabetes.csv',index = False,header=True)

print(train.head())
